package handler;

import java.util.List;
import java.util.Map;

import com.hn.comm.excel.ExcelHandler;
import com.hn.comm.excel.ExcelModel;
import com.hn.shoutchinese.othertrans.service.impl.OtherTransServiceImpl;
import com.hn.shoutchinese.sentence.model.SentenceCombin;

public class OtherTransHandler extends BaseHandler {
	
	public void startWork()
	{

		OtherTransServiceImpl ots = new OtherTransServiceImpl();

		ExcelModel eModel = ExcelHandler.getExcelData(BaseHandler
				.getExcelFile());

		// 得到单个
		int iCount=0;
		for (Map<String, String> map : eModel.getContent()) {
			iCount++;
			// 得到例句
			String othertrans = map.get(HEAD_OTHER_TRANS);
//			othertrans = othertrans.trim();
			if (othertrans == null || othertrans.equals("null")
					|| othertrans.equals("")) {
				// 得到中文
				String chinese = map.get(HEAD_CHINESE);
				// 得到英文
				String english = map.get(HEAD_ENGLISH);

				// 得到词组
				List<String> arrWords = ots.getOtherTransWords(chinese);
				System.out.println("当前个数是"+iCount+",正在寻找,("+chinese+")");
				if (arrWords != null) {
					for (String word : arrWords) {
						// 如果不是当前的翻译，那么写入
						if (!word.trim().equals(english.trim())) {
							map.put(HEAD_OTHER_TRANS, word);
							break;
						}
					}
				}
			}
			//如果还为空或null,那么写入空格
			if (map.get(HEAD_OTHER_TRANS) == null || map.get(HEAD_OTHER_TRANS).equals("null")
					|| map.get(HEAD_OTHER_TRANS).equals("")) {
				map.put(HEAD_OTHER_TRANS, "");
			}
		}

		ExcelHandler.writeExcel(eModel, BaseHandler.getExcelFile());
		System.out.println("寻找其他翻译完成。。。。。");
	}

	public static void main(String[] args) {
		OtherTransHandler oth=new OtherTransHandler();
		oth.startWork();
	}
}
